package jee.boot.module.oauth2.auth;

import jee.boot.module.oauth2.auth.verification.*;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * 默认的账户验证处理器
 */
public class DefaultAccountValidator implements AccountValidator {
    private List<AccountVerificationFilter> beforeAuthenticateFilters = new ArrayList<>();
    private List<AccountVerificationFilter> afterAuthenticateFilters = new ArrayList<>();

    public DefaultAccountValidator() {
    }

    public DefaultAccountValidator(RedisTemplate<String, Object> redisTemplate) {
        //添加前置验证
        addBeforeAuthenticateFilters(new ImageCodeVerification(redisTemplate));//添加图片验证码的验证处理器
        addBeforeAuthenticateFilters(new AccountLockedVerification());// 账户锁定验证

        //添加后置验证
        addAfterAuthenticateFilters(new AccountExpiredVerification());// 账户过期验证
        addAfterAuthenticateFilters(new PasswordExpiredVerification());// 密码过期验证

    }

    public AccountValidator addBeforeAuthenticateFilters(AccountVerificationFilter accountVerificationFilter) {
        getBeforeAuthenticateFilters().add(accountVerificationFilter);
        return this;
    }

    public AccountValidator addAfterAuthenticateFilters(AccountVerificationFilter accountVerificationFilter) {
        getAfterAuthenticateFilters().add(accountVerificationFilter);
        return this;
    }

    public List<AccountVerificationFilter> getBeforeAuthenticateFilters() {
        return beforeAuthenticateFilters;
    }

    public List<AccountVerificationFilter> getAfterAuthenticateFilters() {
        return afterAuthenticateFilters;
    }
}
